﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace BanHangCshap.Class
{
    public static class CauHinhHeThong
    {
        public static Boolean hoineubanam = false;
        public static Boolean tusinhma = false;
        public static Boolean tuketchuyen = false;
        public static Boolean tusaoluu = false;
        public static string noiluutru = "";
        public static int thang = 0;
        public static double nam = 0;
        public static void layCauHinhHeThong()
        {
            string sql = "select month(getdate()) as thang, year(getdate()) as nam,hoineubanam,tuketchuyen,tusinhma,tusaoluu,noiluutru from CauHinhHeThong";
            SqlDataAdapter da = new SqlDataAdapter();
            da = new SqlDataAdapter(sql, DatabaseStatic.conn);
            DataTable dt = new DataTable();
            try
            {
                da.Fill(dt);
                foreach (DataRow dr in dt.Rows)
                {
                    hoineubanam = (Boolean)dr["hoineubanam"];
                    tuketchuyen = (Boolean)dr["tuketchuyen"];
                    tusinhma = (Boolean)dr["tusinhma"];
                    tusaoluu = (Boolean)dr["tusaoluu"];
                    noiluutru = dr["noiluutru"].ToString();
                    thang = int.Parse(dr["thang"].ToString());
                    nam = int.Parse(dr["nam"].ToString());
                }
            }
            catch (Exception)
            {
                dt = null;

            }



        }
        public static Boolean suaCauHinhHeThong(Boolean hoineubanam, Boolean tusinhmahang, Boolean tuketchuyen,Boolean tusaoluu, string noiluutru)
        {
            string sql = "Update CauHinhHeThong set hoineubanam = '" + hoineubanam + "', tusinhmahang = '" + tusinhmahang + "', tuketchuyen = '" + tuketchuyen + "', tusaoluu = '" + tusaoluu + "',noiluutru = '" + noiluutru + "'";
            
            SqlCommand cmd = new SqlCommand(sql, DatabaseStatic.conn);
            try
            {
                cmd.ExecuteNonQuery();


            }
            catch (Exception)
            {


                return false;
            }
            return true;
        }
       


    }
}
